const $chars2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
export function randomString(length: number) {
  let id = ''
  for (let i = 0; i < (length || 1); i++) {
    id += $chars2.charAt(Math.floor(Math.random() * $chars2.length))
  }
  return id
}

const HEX_CHARS = '0123456789abcdef'

/**
 * 生成指定长度的随机十六进制字符串
 * @param {number} length - 要生成的字符串长度
 * @returns {string} 随机十六进制字符串
 */
export function randomHexString(length: number): string {
  let result = ''
  for (let i = 0; i < length; i++) {
    result += HEX_CHARS.charAt(Math.floor(Math.random() * 16))
  }
  return result
}
